﻿using System.Runtime.CompilerServices;
using WeDonekRpc.Helper;
using WeDonekRpc.Helper.Validate;

namespace Shop.RemoteModel.PageModule.ModuleConfig
{
    public class PageModuleConfig
    {
        [NullValidate("shop.page.module.name.null")]
        public string ModuleName
        {
            get;
            set;
        }
        /// <summary>
        /// 轮播图片
        /// </summary>
        [EntrustValidate("_CheckConfig")]
        public AdvertPlaceConfig RollAdvert { get; set; }

        /// <summary>
        /// 图片广告
        /// </summary>
        public AdvertPlaceConfig ImgAdvert { get; set; }

        /// <summary>
        /// 图片热点
        /// </summary>
        public ImgWallConfig ImgWall { get; set; }

        /// <summary>
        /// 三页广告图
        /// </summary>
        public TreeAdvertImgConfig TreeAdvert { get; set; }

        /// <summary>
        /// 商品推荐
        /// </summary>
        public SkuRecommend Recommend { get; set; }

        /// <summary>
        /// 商品分类
        /// </summary>
        public SkuTab[] Tabs { get; set; }

        /// <summary>
        /// 菜单列表
        /// </summary>
        public MenusConfig[] Menus { get; set; }

        [MethodImplAttribute(MethodImplOptions.NoOptimization)]
        private void _CheckConfig ( PageModuleConfig config )
        {
            if ( config.ModuleName.IsNull() )
            {
                return;
            }
            else if ( config.ModuleName == "rollAdvert" )
            {
                if ( this.RollAdvert == null )
                {
                    throw new ErrorException("shop.page.module.config.null");
                }
            }
            else if ( config.ModuleName == "imgWall" )
            {
                if ( this.ImgWall == null )
                {
                    throw new ErrorException("shop.page.module.config.null");
                }
            }
            else if ( config.ModuleName == "imgAdvert" )
            {
                if ( this.ImgAdvert == null )
                {
                    throw new ErrorException("shop.page.module.config.null");
                }
            }
            else if ( config.ModuleName == "treeAdvert" )
            {
                if ( this.TreeAdvert == null )
                {
                    throw new ErrorException("shop.page.module.config.null");
                }
            }
            else if ( config.ModuleName == "skuRecommend" )
            {
                if ( this.Recommend == null )
                {
                    throw new ErrorException("shop.page.module.config.null");
                }
            }
            else if ( config.ModuleName == "skuTabs" )
            {
                if ( this.Tabs.IsNull() )
                {
                    throw new ErrorException("shop.page.module.config.null");
                }
            }
            else if ( config.ModuleName == "menus" )
            {
                if ( this.Menus.IsNull() )
                {
                    throw new ErrorException("shop.page.module.config.null");
                }
            }
            else
            {
                throw new ErrorException("shop.page.module.name.error");
            }
        }
    }
}
